#!/bin/env python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    Add By : cdj <e4ting@qq.com> 2021-07-14 17:57:18
"""
from flask_restful import Resource
from flask         import redirect,request,make_response

from urllib.parse import urlparse

from e4ting        import util,log
from e4ting.cache  import UUIDCache
from models.mongos import DB
from e4ting.task   import Anon

from core.webhook.events import EventBaitPot
from core.webhook.hooks  import HookSender

class WebBotDetail(Resource):
    """ 肉鸡详细信息 """

    def get(self, id=None):
        """ 返回肉鸡详细 """
        if not id:
            return {
                "code" : 200,
                "data"  : {},
            }
        item = DB.clients[id]
        if "python" in item.get("User-Agent", ""):
            item["preimg"] = "//img.e4ting.cn/files/upload/c36dccadd99982a2966ea22fe5a1a21c/python-logo-large.c36dccadd999.png"
        elif "curl" in item.get("User-Agent", ""):
            item["preimg"] = "//img.e4ting.cn/files/upload/7c086f6854a5141714dbe55f457fd178/curl.jpg"
        elif item.get("system", None) == "darwin":
            item["preimg"] = "//img.e4ting.cn/files/upload/18c20820f0ac8df484df61d49a49c1b5/mac-os-logo.png"
        elif item.get("version", None):
            item["preimg"] = "//img.e4ting.cn/files/upload/727a3c30b5f34931eadb8957faff6474/golang.png"
        elif item.get("system", None) == "linux":
            item["preimg"] = "//www.e4ting.cn/img/linux.png"
        else:
            item["preimg"] = "//img.e4ting.cn/files/upload/cb658a580cb575412e66a8b78816bd8d/chrome.svg"

        item["ttyd"] = "https://{_id}.e4ting.cn/0/tty".format(**item)
        item["consul"] = "http://consul.e4ting.cn/ui/antiy/kv/e4ting/nodes/{_id}/".format(**item)
        return {
            "code" : 200,
            "data"  : item,
        }
